#include "ADC.h"




void Delay(unsigned int n)
{
    unsigned int x;

    while (n--)
    {
        x = 5000;
        while (x--);
    }
}


void InitADC()
{
    P1ASF = 0xff;                  
    ADC_RES = 0;                    
	ADC_CONTR = ADC_POWER | ADC_SPEEDLL;
    Delay(2);                      
}



unsigned char GetADCResult(unsigned char ch)
{
    ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START;
    Delay(2); 
    while (!(ADC_CONTR & ADC_FLAG));
    ADC_CONTR &= ~ADC_FLAG;         

    return ADC_RES;                
}





